<template>
  <div>
    <el-form ref="pram" :model="pram" :rules="rules" label-width="100px" @submit.native.prevent>
      <el-form-item label="开始时间" prop="startTime" class="dislabel">
        <el-date-picker v-model="pram.startTime" value-format="yyyy.MM" format="yyyy.MM" size="small" type="month" placement="bottom-end" style="width: 100%;" @change="onchangeStartTime" placeholder="开始时间"/>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime" class="dislabel">
        <el-date-picker v-model="pram.endTime" value-format="yyyy.MM" format="yyyy.MM" size="small" type="month" placement="bottom-end" style="width: 100%;" @change="onchangeEndTime" placeholder="结束时间"/>
      </el-form-item>
      <el-form-item label="内容" prop="content" class="dislabel">
        <el-input v-model="pram.content" type="textarea"  maxlength="250" :rows="4" placeholder="请输入工作单位及职务" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handlerSubmit('pram')" v-hasPermi="['admin:person:update','admin:person:save']">{{ isCreate===0?'确定':'更新' }}</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {Debounce} from '@/utils/validate'
export default {
  // name: "edit"
  components: { },
  props: {
    isCreate: {
      type: Number,
      required: true
    },
    editData: {
      type: Object,
      default: () => {
        return { rules: [] }
      }
    },
    editKey: {
      type: Number,
      required: true,
      default: -1,
    }
  },
  data() {
    return {
      constants:this.$constants,
      pram: {
        startTime: null,
        endTime: null,
        timeRange: null,
        content: null,
        id: null,
      },
      rules: {
        startTime: [{ required: true, message: '请选择开始时间', trigger: ['blur', 'change'] }],
        endTime: [{ required: true, message: '请选择结束时间', trigger: ['blur', 'change'] }],
        content: [{ required: true, message: '请填写内容', trigger: ['blur', 'change'] }],
      },
    }
  },
  watch:{
    'pram.startTime':{
      handler(val){
        this.pram.timeRange = val + ' -- ' + this.pram.endTime
      }
    },
    'pram.endTime':{
      handler(val){
        this.pram.timeRange = this.pram.startTime + ' -- ' + val
      }
    },
  },
  mounted() {
    this.initEditData()
  },
  methods: {
    close() {
      this.$emit('hideResumeDialog')
    },

    onchangeStartTime (e) {
      this.pram.startTime = e;
    },
    onchangeEndTime (e) {
      this.pram.endTime = e;
    },

    initEditData() {
      if (this.isCreate !== 1) return //编辑
      const { id, startTime, endTime, content} = this.editData //通过list中slot-scope=“scope“，scope.$index就是该行的下标，scope.row就是该行的数据所有消息对象，有了这两个参数就可以实现编辑、删除功能（this.editData就是scope.row传入的对象参数）
      this.pram.id = id
      this.pram.startTime = startTime
      this.pram.endTime = endTime
      this.pram.content = content
    },
    handlerSubmit:Debounce(function(form) {
      this.$refs[form].validate(valid => {
        if (!valid) return
        if (this.isCreate === 0) {
          this.handlerSave()
        } else {
          this.handlerEdit()
        }
      })
    }),
    handlerSave() {
      this.$emit('assignResumeSaveAndHideResumeDialog',this.pram)
    },
    handlerEdit() {
      this.$emit('assignResumeEditAndHideResumeDialog',this.pram,this.editKey)
    },
  }
}
</script>

<style scoped lang="scss">
  .dislabel{
    ::v-deep.el-input--small .el-input__inner,
    ::v-deep.el-input--medium .el-input__inner{
      height:36px;
      line-height:36px;
      font-size:12px;
    }
    ::v-deep.el-textarea__inner{
      font-size:12px;
    }

  }
</style>
